package com.betterjr.modules.customer.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.betterjr.common.service.BaseService;
import com.betterjr.common.utils.BTAssert;
import com.betterjr.modules.customer.dao.CustCloudPlatformCustomMapper;
import com.betterjr.modules.customer.entity.CustCloudPlatformCustom;

/**
 * 
 * @ClassName: CustCloudPlatformCustomService 
 * @Description: 云平台客户相关信息操作
 * @author xuzx
 * @date 2018年1月19日 下午2:57:54 
 *
 */
@Service
public class CustCloudPlatformCustomService
        extends BaseService<CustCloudPlatformCustomMapper, CustCloudPlatformCustom> {

    @Autowired
    private CustOpenAccountTmpService custOpenAccountTmpService;

    /**
     * 
     * @Title: saveCloudPlatformCustomer 
     * @Description: 根据是否已存，选择插入或更新客户信息 
     * @param custCloudPlatformCustomList 客户信息列表
     * @param anOperorg 操作机构
     * @throws 
     * @author xuzx
     * @date 2018年1月19日 下午2:58:11
     */
    @SuppressWarnings("unused")
    public void saveCloudPlatformCustomer(final List<CustCloudPlatformCustom> custCloudPlatformCustomList,
            final String anOperorg) {
        BTAssert.notNull(custCloudPlatformCustomList, "传入对象为空！");
        BTAssert.notNull(anOperorg, "传入操作机构为空！");
        List<CustCloudPlatformCustom> customList = custCloudPlatformCustomList;
        for (CustCloudPlatformCustom customInfo : customList) {
            CustCloudPlatformCustom custom = selectByPrimaryKey(customInfo.getEnteID());
            if (custom != null) {
                custom.setCorpName(customInfo.getCorpName());
                custom.setOcc(customInfo.getOcc());
                custom.setSuperId(customInfo.getSuperId());
                custom.setCorpCode(customInfo.getCorpCode());
                this.updateByPrimaryKey(custom);
            } else {
                customInfo.initAddValue(customInfo);
                customInfo.setOperorg(anOperorg);
                this.insert(customInfo);
            }
        }
    }

}
